<?php

class Login extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
        $this->load->model('loginmodel');
    }

	public function index()
	{
		$logat = $this->loginmodel->este_logat();
		if($logat)
		{
			redirect('home');
		}
		else
		{			
			$this->form_validation->set_rules('password', 'Parola', 'required|min_length[6]');
			$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
			if ($this->form_validation->run() == FALSE)
			{				
				$data = array('titlu' => 'Star Cinema | Autentificare');
				$this->load->view('home/header', $data);
				$this->load->view('login/insucces');
			}
			else
			{
				$email = $this->input->post('email');	
				$parola = $this->input->post('password');
				$login = $this->loginmodel->autentifica($email, $parola);				
				if($login == 1)
				{
					redirect(base_url()); 
				}
				else
				{					
					$data = array('title' => 'Red Light Cinema | Autentificare');				
					$this->load->view('home/header', $data);
					$this->load->view('login/insucces2', $data);
				}				
			}
			$this->load->view('home/footer');
		}
	}

	public function logout()
	{
		$this->loginmodel->logout();
		redirect(base_url());
		exit;
	}

}
?>